package com.bristua.barcode.customer.biz;

import com.bristua.barcode.common.util.DateUtils;
import com.bristua.barcode.common.util.SequenceUtil;
import com.bristua.barcode.customer.dao.TCustomerAccountMapper;
import com.bristua.barcode.customer.dao.TCustomerMapper;
import com.bristua.barcode.customer.model.TCustomer;
import com.bristua.barcode.customer.model.TCustomerAccount;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/8/6 0006.
 */
@Transactional
@Service
public class AddCustomerBiz {

    @Resource
    private TCustomerMapper tCustomerMapper;


    @Resource
    private TCustomerAccountMapper tCustomerAccountMapper;


    public void addCustomer(String customerNo,String customerName){
        TCustomer tCustomer = new TCustomer();
        tCustomer.setCustomerId(SequenceUtil.nextId());
        tCustomer.setCustomerName(customerName);
        tCustomer.setCustomerNo(customerNo);
        tCustomer.setStatus(1);
        tCustomer.setCreateTime(DateUtils.getShowDateTime());
        tCustomerMapper.insert(tCustomer);

        TCustomerAccount tCustomerAccount = new TCustomerAccount();
        tCustomerAccount.setCustomerAccountId(SequenceUtil.nextId());
        tCustomerAccount.setCustomerId(tCustomer.getCustomerId());
        tCustomerAccount.setAccountAmt(0L);
        tCustomerAccount.setCreateTime(DateUtils.getShowDateTime());

        tCustomerAccountMapper.insert(tCustomerAccount);
    }
}
